﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using System.Xml.Linq;
using System.Xml;
using System.Diagnostics;

namespace YLClient.Froms
{
    /// <summary>
    /// Interaction logic for FrmNetSetting.xaml
    /// </summary>
    public partial class FrmNetSetting : Window
    {
        XAttribute address;
        XDocument doc;
        string config;
        public FrmNetSetting()
        {
            InitializeComponent();
            var file = Environment.CurrentDirectory;
            var dir = Common.getDir(file);
            config = dir + "\\" + Process.GetCurrentProcess().ProcessName + ".exe.config";
            doc = XDocument.Load(config);
            address =
                doc.Element(XName.Get("configuration"))
                .Element(XName.Get("system.serviceModel"))
                .Element(XName.Get("client"))
                .Element(XName.Get("endpoint"))
                .Attribute(XName.Get("address"));
            txtAddress.Text = address.Value;

        }

        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("确定修改？", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                address.Value = txtAddress.Text;
                doc.Save(config);
                GlobalClass.DataContainer.Dict["address"] = address.Value;
                this.Close();
            }
        }
    }
}
